package com.demo.main;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class Draw  implements ApplicationContextAware,BeanNameAware,InitializingBean{
	
	
	@Autowired
	private Triangle triangle;
	
	@Autowired(required=true) 
	private Rectangle rectangle;

	
	private ApplicationContext  applicationContext;
	
	
	
	public void draw(){
		setTriangle(applicationContext.getBean("tringle",Triangle.class));
		
		
		System.out.println("drawing tringle"+ triangle);
		System.out.println("drawing rectangle"+rectangle);
		
		
		
	}




	public Triangle getTriangle() {
		return triangle;
	}




	public Rectangle getRectangle() {
		return rectangle;
	}




	public void setTriangle(Triangle triangle) {
		this.triangle = triangle;
	}




	public void setRectangle(Rectangle rectangle) {
		this.rectangle = rectangle;
	}




	@Override
	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		
		this.applicationContext=applicationContext;
	}
	

	
	@Override
	public void setBeanName(String name) {
		System.out.println("Bean name is being  set :::: "+name);
		ApplicationUtils.BEANNAME_LIST.add(name);
	}
	
	@Override
	public void afterPropertiesSet() throws Exception {
	 System.out.println(" in init method ....");	
	}
	
}
